package com.tony.demo.mvp.presenter.impl;

import com.puhui.lib.base.mvp.IView;
import com.tony.demo.mvp.presenter.interfaces.IBasePresenter;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.lang.ref.WeakReference;

/**
 * Copyright:
 * Created by TangJian on 2019/4/17.
 * Description:
 * Modified:
 */
@SuppressWarnings("unused")
public abstract class BasePresenter<V extends IView> implements IBasePresenter<V> {
    protected WeakReference<V> mView;

    @Override
    public void attachView(V view) {
        EventBus.getDefault().register(this);
        mView = new WeakReference<>(view);
    }

    @Override
    public void detachView() {
        EventBus.getDefault().unregister(this);
        mView.clear();
    }

    @Subscribe(threadMode = ThreadMode.POSTING)
    public void baseEvent(String baseEvent) {
    }
}
